﻿@model ContentPicker
@{
    // get config object
    var confObj = this.Model.GetConfigObject<ContentPickerConfigObject>();

    // add js
    Html.AddToBackEndContent("~/Areas/Proggy/Content/Scripts/Proggy.SiteMap.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/Proggy.CorePropertyTypes.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/Proggy.CorePropertyTypes.ContentPicker.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Css/ContentPicker.css", BackEndContentType.Stylesheet);
    Html.RenderBackEndContentForLightboxPartial();

    // get id
    var id = Model.GetUniqueElementId("", "");

    // get picker id
    var pickerId = Model.GetUniqueElementId("", "");
}
<noscript><div class="proggy-noscript">THIS EDITOR WILL NOT WORK WITHOUT JAVASCRIPT TURNED ON AND IT WOULD BE DANGEROUS TO USE THE EDITOR WHILST JAVASCRIPT IS TURNED OFF. PLEASE TURN JAVASCRIPT ON.</div></noscript>
<div class="proggy-rp" id="@(id)">
    <div class="proggy-rp-addnew">
        @Html.ActionLink("Add new", "ContentPicker", new { controller = "ContentPicker", area = "ProggyCore", pickerId = pickerId }, new { @class = "proggy-button" })
    </div>
    <div class="proggy-rp-added">
        <h5>
            Already added:</h5>
        @{
            Html.RenderAction("ContentPickerItems", new { area = "ProggyCore", controller = "ContentPicker", items = Model.ContentIds });    
        }
    </div>
    <div class="proggy-rp-inputs">
        @{
            // start counter
            var counter = 0;

            // check
            if (Model.ContentIds != null)
            {

                // iterate
                foreach (var item in Model.ContentIds)
                {
                    // get name
                    var name = Model.PropertyNameStart + ".ContentIds[" + counter + "]";

                    // render
            @:@Html.Hidden(name, item)

                    // add to counter
                    counter++;
                }
            }
        }
    </div>
</div>
<script type="text/javascript">

    //
    Proggy.Static.WaitForTypesToRegister(function () {

        // 
        var cp = new Proggy.CorePropertyTypes.ContentPicker();
        cp.Init("@(id)", "@(pickerId)", "@(Model.PropertyNameStart)");

    });

</script>
